/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logica;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 *
 * @author Fernando
 */
public class Link implements Serializable{
    private String nameLink;
    private String user;
    private String pass;
    private String host;
    private String port;
    private String db;
    
    public Link(){
        this.nameLink = "";
        this.user = "";
        this.pass = "";
        this.host = "";
        this.port = "";
        this.db = "";
    }
    
    public Link(String nl, String us, String pa, String ho, String po, String db){
        this.nameLink = nl;
        this.user = us;
        this.pass = pa;
        this.host = ho;
        this.port = po;
        this.db = db;
    }
    
    public String getNameLink() {
        return nameLink;
    }

    public void setNameLink(String nameLink) {
        this.nameLink = nameLink;
    }
    
    public String getUser() {
        return user;
    }

    
    public void setUser(String user) {
        this.user = user;
    }

    
    public String getPass() {
        return pass;
    }

    
    public void setPass(String pass) {
        this.pass = pass;
    }

    
    public String getHost() {
        return host;
    }

    
    public void setHost(String host) {
        this.host = host;
    }

    
    public String getPort() {
        return port;
    }

    
    public void setPort(String port) {
        this.port = port;
    }

    
    public String getDb() {
        return db;
    }

    
    public void setDb(String db) {
        this.db = db;
    }
    
    @Override
    public String toString(){
        
        StringBuilder s = new StringBuilder();
        s.append(String.format(this.nameLink+"\n"));
        s.append(String.format(this.user+"\n"));
        s.append(String.format(this.pass+"\n"));
        s.append(String.format(this.host+"\n"));
        s.append(String.format(this.port+"\n"));
        s.append(String.format(this.db+"\n"));
        return s.toString();
    }
    
    public boolean guardar(String arch){
        try
      {
         FileOutputStream fileOut = new FileOutputStream(arch,true);
         ObjectOutputStream out =  new ObjectOutputStream(fileOut);
         out.writeObject(this);
         out.close();
         fileOut.close();
      }catch(IOException i)
      {
          i.printStackTrace();
          return false;
      }

        return true;
    }
    
    public Link cargar(String arch) {
        Link obj;
        try {
            FileInputStream fis = new FileInputStream(arch);
            ObjectInputStream ois = new ObjectInputStream(fis);

            obj = (Link) ois.readObject();

            ois.close();
            fis.close();
            System.out.print("CARGA");
        } catch (IOException e) {
            //e.printStackTrace();
            return null;
        } catch (ClassNotFoundException e) {
            //e.printStackTrace();
            return null;
        }
   
        return obj;
    }

    
}
